package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.CompanyT;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

/**
 * 获取微信公众号素材接口dao
 *
 */
@MapperScan
public interface WeChatGetMaterialDao {
	//根据服务渠道id获取素材
    @Select("<script> select * from WeChatGetMaterial_T where CompanyId in <foreach collection='CompanyIds' item='item' open='(' separator=',' close=')'>#{item} </foreach> and Flag=0 and title != '' and ThumbUrl != '' order by MaterialnUpdateTime desc </script>")
    List<Map<String, Object>> getWeChatGetMaterialList(@Param("CompanyIds") List<String> CompanyIds);


    //把从微信上获取到的素材批量插入到数据库中
    int insert(Map<String,Object> map);

    //根据服务渠道id所有媒体id
    @Select("select MaterialnMediaId from WeChatGetMaterial_T where CompanyId =#{CompanyId} order by MaterialnUpdateTime desc")
    List<String> getMaterialnMediaIdList(@Param("CompanyId")long CompanyId);

	//把从微信上获取到的素材根据MaterialnMediaId去匹配   匹配上的修改
	@Update("update WeChatGetMaterial_T set title = #{title} ,author=#{author} ,digests =#{digests},ThumbMediaId=#{ThumbMediaId},ContentUrl=#{ContentUrl},ThumbUrl=#{ThumbUrl},CoverWidth=#{CoverWidth},CoverHeight=#{CoverHeight},\n" +
			"MaterialnCreateTime=#{MaterialnCreateTime},MaterialnUpdateTime=#{MaterialnUpdateTime},Updator=#{Updator},UpdateTime=#{UpdateTime} where MaterialnMediaId=#{MaterialnMediaId}  and title = #{title}")
	int update(Map<String,Object> map);

	@Select("select count(ID) from WeChatGetMaterial_T where CompanyId = #{CompanyId}")
	int getWeChatGetMaterialCountByCompanyId(@Param("CompanyId")long CompanyId);

	@Select("select count(ID) from WeChatGetMaterial_T where Creator = #{CreatorId}")
	int getWeChatGetMaterialCountByCreatorId(@Param("CreatorId")long CreatorId);

}
